<?php

namespace app\common\middleware;



use app\common\tools\Redis;
use think\facade\Cache;

/**
 * 访问量统计
 * Class Visit
 * @package app\common\middleware
 */
class Visit
{
    public function handle($request, \Closure $next)
    {
        $date = date('Y-m-d');
        $cacheKey = md5($request->ip().$date);
        if (!Cache::has($cacheKey)) {
            \app\common\model\Visit::create([
                'ip' => $request->ip(),
            ]);
            Cache::set($cacheKey, 1, 60 * 60 * 24);
        }
        return $next($request);
    }
}
